package com.vchello.util;

import java.io.IOException;
import java.util.Properties;

/**
 * 读取配置文件
 * 
 * @author power
 * @time 2015年12月2日上午9:23:51
 */
public class ReadPropertyUtil {

    public static Properties props = new Properties();

    static {
	try {
	    props.load(ReadPropertyUtil.class.getClassLoader()
		    .getResourceAsStream("config.properties"));
	} catch (IOException e1) {
	    e1.printStackTrace();
	}
    }

    /** 私有构造方法 */
    private ReadPropertyUtil() {

    }

    /** 获取实例 */
    public static ReadPropertyUtil getInstance() {
	ReadPropertyUtil rp = new ReadPropertyUtil();
	// 初始化数据库连接类型
	return rp;
    }

    /** 获取资源文件里对应 key=value 中的value的值 */
    public static String getProperty(String key, String defaultValue) {
	String value = props.getProperty(key);

	return ToolUtil.isNotEmpty(value) ? value : defaultValue;
    }

    /** 转换字符串 */
    public String CheckReplace(String s) {
	char[] arr = s.toCharArray();
	for (int i = 0; i < arr.length; i++) {
	    if ((int) arr[i] == 92) {
		arr[i] = '/';
	    }
	}
	s = new String(arr);
	return s;
    }

    @SuppressWarnings("static-access")
    public static void main(String[] args) {
	ReadPropertyUtil r = ReadPropertyUtil.getInstance();
	System.out.println("managerEmail邮箱:\t" + r.getProperty("managerEmail", ""));
    }
}